%% Author: maciek
%% Created: 14-04-2011
%% Description: TODO: Add description to iax2_utils
-module(iax2_utils).
-compile(export_all).
-export([md5_challenge_response/2,get_timestamp/0]).

md5_challenge_response(Pass,Challenge) ->
	L=binary_to_list(crypto:md5(Challenge++Pass)),
	lists:foldl(fun(X,Acc) -> 
					if X<16 ->	
						Acc++"0"++string:to_lower(integer_to_list(X,16));
					 true ->  
						Acc++string:to_lower(integer_to_list(X,16))	
					end 
				end,"", L).
	

get_timestamp() ->
    {Mega,Sec,Micro} = erlang:now(),
    trunc(((Mega*1000000+Sec)*1000000+Micro)/1000).

test() ->
	md5_challenge_response("test","12105348").